/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gblend.formatcovert;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
/*
* Copyright 2010, Center for Advanced Information Systems, Nanyang Technological University
*
* File name: IdlistConvert.java
*
* Abstract: Convert the idlist format
*
* Current Version:      0.1
* Auther:               Jin Changjiu
* Modified Date:        June.3,2009
*
*/
/**
 *
 * @author ibmuser
 */
public class IdlistConvert {

    private static String filename =null;
    public static void main (String[] args) throws FileNotFoundException, IOException
    {
         filename = "data/Syn/10k/0.05Syn10k";
         formatDotFile(filename);
    }

    public static void formatDotFile(String filename) throws FileNotFoundException, IOException
    {
        String output1=filename+".txt";
        String strLine = null;
	FileOutputStream outStream1;
	PrintStream p;
        PrintStream q;
	FileInputStream inStream;
	DataInputStream in;
	BufferedReader br;

	File fin=new File(filename);
	File fout1=new File(output1);
        if(fin.exists())
	{

                    outStream1=new FileOutputStream(fout1,false);
                    inStream=new FileInputStream(fin);
                    // Connect print stream to the output stream
                    p = new PrintStream( outStream1 );
                    // Get the object of DataInputStream
                    in = new DataInputStream(inStream);
                    br = new BufferedReader(new InputStreamReader(in));
				//Read file line by line

                    
                    strLine = br.readLine();
                    while (!strLine.contains("idlist"))
                    {
                         p.println(strLine);
                         strLine = br.readLine();
                    }
                    p.println("idlist");
                    while ((strLine = br.readLine()) != null)
                    {
                        int num = Integer.parseInt(strLine);
                        for(int i = 0; i< num; i++)
                        {
                            strLine = br.readLine();
                            int spport = Integer.parseInt(strLine);
                            p.print(spport+" ");

                        }
                        p.println();
                    }

                    //Close the input stream
                    in.close();
                    p.close();

        }

  }
}
